/** Invoice Class */

package edu.gatech.datastorage;
import java.io.Serializable;
import java.text.NumberFormat;

/** This class corresponds with Patient Information to assist in 
 * 'printing' the current invoice.
 * @author Will Folsom 
 * @version 1.0 */

public class Invoice implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -6729373817742190834L;

	/** This int, amountOwed, will be take the amount owed from
	 * patient, and be manipulated by this class */
	private int amountOwed;
	
	/**All of the different quantities expenses**/
	private int shots, xrays, checkUps, bloodWork, surgery;
	
	/**All of the total values of the expenses*/
	private int totalShots, totalXrays, totalCheckUps, totalBloodWork, totalSurgery;
	
	/**Price of shot*/
	private static final int SHOTPRICE = 40;
	
	/**Price of xray**/
	private static final int XRAYPRICE = 100;
	
	/**Price of checkUp**/
	private static final int CHECKUPPRICE = 50;
	
	/**Price of bloodWork**/
	private static final int BLOODWORKPRICE = 40;
	
	/**Price of surgery**/
	private static final int SURGERYPRICE = 100000;
	
	/**Boolean that tells the treatment record an invoice has been calculated**/
	private boolean invoiceCalculated;
	
	/** This NumbderFormat allows for the amount owed to be returned
	 * in a USD currency format. */
	private NumberFormat usdFormat = NumberFormat.getCurrencyInstance();

	/**Constructor to calculate invoice
	 * 
	 * @param shots
	 * @param xrays
	 * @param checkUps
	 * @param bloodWork
	 * @param surgery
	 */
	public Invoice(int shots, int xrays, int checkUps, int bloodWork, int surgery){
		this.shots = shots;
		this.xrays = xrays;
		this.checkUps = checkUps;
		this.bloodWork = bloodWork;
		this.surgery = surgery;
		amountOwed  = 0;
		totalShots = 0;
		totalXrays = 0;
		totalCheckUps = 0;
		totalBloodWork = 0;
		totalSurgery = 0;
		invoiceCalculated = false;
	}

	/** Gets the total number of shots
	 * 
	 * @return int
	 */
	public int getShots() {
		return shots;
	}

	/** Gets the total number of xrays
	 * 
	 * @return int
	 */
	public int getXrays() {
		return xrays;
	}

	/** Gets the total number of checkups
	 * 
	 * @return int
	 */
	public int getCheckUps() {
		return checkUps;
	}

	/** Gets the bloodwork
	 * 
	 * @return int
	 */
	public int getBloodWork() {
		return bloodWork;
	}

	/** Gets how many surgeries 
	 * 
	 * @return int
	 */
	public int getSurgery() {
		return surgery;
	}

	/** printBill method returns the invoice as a string.
	 * @return invoice string */
	public String printBill(){
		final String temp = usdFormat.format(amountOwed);
		String bill = "";
		bill = "Amount of shots: " + shots + " at $" + SHOTPRICE + " each.\n";
		bill = bill + "Number of xrays: " + xrays + " at $" + XRAYPRICE + " each.\n";
		bill = bill + "Check up: " + checkUps + " at $" + CHECKUPPRICE + ".\n";
		bill = bill + "Amount of bloodwork done: " + bloodWork + " at $" + 
		BLOODWORKPRICE + " each.\n";
		bill = bill + "Surgery: " + surgery + " at $" + SURGERYPRICE + ".\n";
		String contact = "\n\nYou can contact our finance department at" +
				" 1-800-867-5309 \n" +
				"to pay the bill. Thank you!";
        return bill + "\nYour total amount owed is: " + temp + contact;
	}
	
	/**Calculates the total price**/
	public void calculate(){
		totalShots = shots * SHOTPRICE;
		totalXrays = xrays * XRAYPRICE;
		totalCheckUps = checkUps * CHECKUPPRICE;
		totalBloodWork = bloodWork * BLOODWORKPRICE;
		totalSurgery = surgery * SURGERYPRICE;
		amountOwed = totalShots + totalXrays + totalCheckUps 
		+ totalBloodWork + totalSurgery;
		invoiceCalculated = true;
	}
	
	/** Gets the total price of shots
	 * 
	 * @return int
	 */
	public int getTotalShots() {
		return totalShots;
	}
	
	/** Gets the total price of xrays
	 * 
	 * @return int
	 */
	public int getTotalXrays() {
		return totalXrays;
	}
	
	/** Gets the total price of checkups
	 * 
	 * @return int
	 */
	public int getTotalCheckUps() {
		return totalCheckUps;
	}

	/** Gets the total price of blood work
	 * 
	 * @return int
	 */
	public int getTotalBloodWork() {
		return totalBloodWork;
	}

	/** Gets the total price of surgery
	 * 
	 * @return int
	 */
	public int getTotalSurgery() {
		return totalSurgery;
	}

	/** toString overwrites the Object toString, and does
	 * the same thing printBill does.
	 * @return invoice string */
	public String toString(){
		final String temp = usdFormat.format(amountOwed);

        return "Your amount owed is: " + temp;
	}
	
	/** Edits an invoice and recalculates the total
	 * 
	 * @param shots
	 * @param xrays
	 * @param checkUps
	 * @param bloodWork
	 * @param surgery
	 */
	public void editInvoice(int shots, int xrays, int checkUps, 
			int bloodWork, int surgery){
		this.shots = shots;
		this.xrays = xrays;
		this.checkUps = checkUps;
		this.bloodWork = bloodWork;
		this.surgery = surgery;
		calculate();
	}

	/** Checks if the invoice has been calculated
	 *  for the treatment record.
	 * @return boolean
	 */
	public boolean isInvoiceCalculated() {
		return invoiceCalculated;
	}
	
	/**Gets the total amount owed
	 * 
	 * @return int
	 */
	public int getAmountOwed(){
		return amountOwed;
	}
}